package com.webridge.plm.datautility;

import java.util.ArrayList;

import org.apache.log4j.Logger;

import wt.fc.Persistable;
import wt.fc.PersistenceHelper;
import wt.part.WTPart;
import wt.util.WTException;

import com.ptc.core.components.descriptor.ModelContext;
import com.ptc.core.components.factory.AbstractDataUtility;
import com.ptc.core.components.factory.dataUtilities.AttributeDataUtilityHelper;
import com.ptc.core.components.factory.dataUtilities.DefaultDataUtility;
import com.ptc.core.components.rendering.guicomponents.ComboBox;
import com.ptc.core.components.rendering.guicomponents.GUIComponentArray;
import com.ptc.core.components.rendering.guicomponents.GuiComponentUtil;
import com.ptc.core.components.rendering.guicomponents.TextBox;
import com.ptc.core.meta.type.common.impl.DefaultTypeInstance;
import com.ptc.core.ui.resources.ComponentMode;

/**
 * SequenceNumber DataUtility
 * 
 * @author kira
 */
public class SequenceNumberDataUtility extends AbstractDataUtility {
    private static Logger logger = Logger.getLogger(SequenceNumberDataUtility.class.getName());

    @Override
    public Object getDataValue(String componentId, Object datum, ModelContext modelContext) throws WTException {

        logger.debug("English name datautility is coming ");
        ComponentMode componentModel = modelContext.getDescriptorMode();
        String actionType = componentModel.toString();
        logger.debug("actionType en:" + actionType +",componentModel:" + componentModel.toString());
        GUIComponentArray array = new GUIComponentArray();
        if (componentModel.equals(ComponentMode.CREATE)
                || componentModel.equals(ComponentMode.EDIT)) { 
	        /*TextBox textBox = GuiComponentUtil.createTextBox(50);
	        textBox.setId(componentId);
	        textBox.setEnabled(true);
	        textBox.setColumnName(AttributeDataUtilityHelper.getColumnName(componentId, datum, modelContext));
	        if (componentModel.equals(ComponentMode.EDIT)) {
	        	logger.debug("edit english name is coming = ");
	        	logger.debug("attribute container = "+((DefaultTypeInstance)datum).getAttributeContainer().get(modelContext.getATI()));
	        	if (((DefaultTypeInstance)datum).getAttributeContainer().get(modelContext.getATI()) != null) {	        		
	        		String value = ((DefaultTypeInstance)datum).getAttributeContainer().get(modelContext.getATI()).toString();
	        		textBox.setValue(value);        		
	        	}
	        }
//          textBox.setValue("EN");//设置值
	        textBox.addJsAction("onChange", "sequenceChange()");
	        textBox.setRequired(true);
	        //textBox.addJsAction("onblur", "validateENName()");//validate EN Names
	        array.addGUIComponent(textBox);*/
	        
	        
	        ArrayList<String> values = new ArrayList<String>();
            values.add("");
            values.add("YES");
            values.add("NO");
            ArrayList<String> keys = new ArrayList<String>();
            keys.add("");
            keys.add("YES");
            keys.add("NO");
            ArrayList<String> selects = new ArrayList<String>();
            selects.add("NO");
            ComboBox comboxBox = new ComboBox(keys, values, selects);
            comboxBox.setId(componentId);
            comboxBox.setMultiSelect(false);
            comboxBox.addJsAction("onChange", "sequenceChange(this)");
	        logger.debug("array = "+array);
	        array.addGUIComponent(comboxBox);
	        return array;
        }
        return null;    
    }
}
